// 数值型
let isDone: boolean = false;
let num: number = 20;
let hex: number = 0x14;
let bina: number = 0b10100;
let octal: number = 0o24;

// 字符串
let names: string = 'bob'; 
let nameform: string = 'zhang';
let age: number = 30;
let sentence = `Hello, my name is ${nameform}.
    I'll be ${age + 1} year old next month.
` // 模版字符串

// 元组
let x: [string, number]
x = ['zhang', 39]

// 枚举类型

enum Color {
    Red = 1,
    Green = 2,
    Blue = 33,
}

let c:Color = Color.Green
let colorName: string = Color[2]

console.log(colorName)

// any类型 好用但是要慎用
let abc: any

abc = 'good to see you'
abc = true
abc = 123


// void 类型
// 没有任何类型
function warnUser(): void{
    console.log('nice to see you but i cant say any thing')
}

// null 和 undefined
let nums: number | null = 3
nums = null

// never 类型
// 函数里无返回值时使用
function error(message: string): never {
    console.log('talk talk')
    throw new Error(message)
}

function fail() {
    return error('something goes wrong')
}

function inifinite(): never {
    while(true) {

    }
}

// object 类型
declare function create(o: object | null): void;
create({prop: 0})
create(null)


// 推断类型 断言

let someVal: any = 'this is a string'
let stringLength: number = (<string>someVal).length
let stringLength1: number = (someVal as string).length